package com.share.device.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.DeviceStatusLog;
import com.share.device.service.IDeviceStatusLogService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.security.utils.SecurityUtils;

/**
 * 设备状态日志Controller
 *
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/log")
@Tag(name = "设备状态日志", description = "APIs for managing Device Status Logs")
public class DeviceStatusLogController extends BaseController
{
    @Autowired
    private IDeviceStatusLogService deviceStatusLogService;

    /**
     * 查询设备状态日志列表
     */
    @RequiresPermissions("device:log:list")
    @GetMapping("/list")
    @Operation(summary = "设备状态日志列表")
    public TableDataInfo list(DeviceStatusLog deviceStatusLog)
    {
        startPage();
        List<DeviceStatusLog> list = deviceStatusLogService.selectDeviceStatusLogList(deviceStatusLog);
        return getDataTable(list);
    }

    /**
     * 导出设备状态日志列表
     */
    @RequiresPermissions("device:log:export")
    @Log(title = "设备状态日志", businessType = BusinessType.EXPORT)
    @Operation(summary = "导出设备状态日志列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceStatusLog deviceStatusLog)
    {
        List<DeviceStatusLog> list = deviceStatusLogService.selectDeviceStatusLogList(deviceStatusLog);
        ExcelUtil<DeviceStatusLog> util = new ExcelUtil<DeviceStatusLog>(DeviceStatusLog.class);
        util.exportExcel(response, list, "设备状态日志数据");
    }

    /**
     * 获取设备状态日志详细信息
     */
    @RequiresPermissions("device:log:query")
    @Operation(summary = "获取设备状态日志详细信息")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(deviceStatusLogService.selectDeviceStatusLogById(logId));
    }

    /**
     * 新增设备状态日志
     */
    @RequiresPermissions("device:log:add")
    @Operation(summary = "新增设备状态日志")
    @Log(title = "设备状态日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceStatusLog deviceStatusLog)
    {
        deviceStatusLog.setOperator(SecurityUtils.getUsername());
        return toAjax(deviceStatusLogService.insertDeviceStatusLog(deviceStatusLog));
    }

    /**
     * 修改设备状态日志
     */
    @RequiresPermissions("device:log:edit")
    @Operation(summary = "修改设备状态日志")
    @Log(title = "设备状态日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceStatusLog deviceStatusLog)
    {
        deviceStatusLog.setOperator(SecurityUtils.getUsername());
        return toAjax(deviceStatusLogService.updateDeviceStatusLog(deviceStatusLog));
    }

    /**
     * 删除设备状态日志
     */
    @RequiresPermissions("device:log:remove")
    @Operation(summary = "删除设备状态日志")
    @Log(title = "设备状态日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(deviceStatusLogService.deleteDeviceStatusLogByIds(logIds));
    }
} 